<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>unique</title>
</head>
<body>
<script src="../jquery-1.7.2.js"></script>
<script>
    function unique(a){
        var seen={};//声明一个空数组
        return a.filter(function(item){
            return seen.hasOwnProperty(item)?false:(seen[item]=true);
        });
    }
    var a = [1,1,3,2,1,2,4];
    var ans = unique(a);
    console.log(ans);
</script>
</body>
</html>